package com.sun.rabbit.routing.direct;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.sun.rabbit.utils.RabbitMqUtils;

import java.util.HashMap;
import java.util.Map;



/**生产者
 * @author shkstart
 * @create 2021-10-16 15:18
 */
public class EmitLogDirect {
    private final static String EXCHANGE_NAME="direct_logs";

    public static void main(String[] args) throws Exception {
        try ( Channel channel = RabbitMqUtils.getChannel();){
            channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT);

            //创建多个bindingKey
            Map<String, String> bindingKeyMap = new HashMap<>();
            bindingKeyMap.put("info","普通info信息");
            bindingKeyMap.put("warning","警告waring信息");
            bindingKeyMap.put("error","错误error信息");
            //debug 没有消费这接收这个消息 所有就丢失了
            bindingKeyMap.put("debug","调试debug信息");
            for(Map.Entry<String, String> bindingKeyEntry:bindingKeyMap.entrySet()){
                String bindingKey = bindingKeyEntry.getKey();
                //发送消息
                String message = bindingKeyEntry.getValue();
                channel.basicPublish(EXCHANGE_NAME,bindingKey,null,message.getBytes("UTF-8"));
                System.out.println("生产者发送消息:"+message);
            }

        }
    }
}
